<?php
 session_start();
 include('../config.php'); 
 $table = $_GET['filename']; // table you want to export
 
 LinkDataBase();
$result = mysql_query("SHOW COLUMNS FROM ".$table."");
 $i = 0;
 
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
//$csv_output .= $row['Field'].";";
$i++;}
}
$csv_output = $_GET["sheet"]."\n";
$csv_output .= $_GET["Qname"];
$csv_output .= "\n";
$sql = "select * from ".$_GET["filename"]." where table_name Like '".str_replace("'","''",$_GET["sheet"])."%'";

$result= mysql_query($sql);
 
while ($rowr = mysql_fetch_row($result)) {
for ($j=0;$j<($i-1);$j++) {
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}

$filename = $_GET["sheet"];
 
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
 
print $csv_output;
 
exit;
?>